const express = require('express');
const router = express.Router();
const {
    register,
    login,
    adminRegister,
    adminLogin
} = require('../controllers/authController');
const { register: registerValidation } = require('../middleware/validator/registerValidator');
const { login: loginValidation } = require('../middleware/validator/loginValidator');
const { validateRequest } = require('../middleware/validator');
const { verifyToken } = require('../utils/jwt');
const { isAdmin } = require('../middleware/adminAuth');

// 注册路由
router.post('/register', registerValidation, validateRequest, register);

// 登录路由
router.post('/login', loginValidation, validateRequest, login);

// 管理员路由
router.post('/admin/register', adminRegister);
router.post('/admin/login', adminLogin);

// 验证管理员权限的示例路由
router.get('/admin/profile', verifyToken(), isAdmin, (req, res) => {
    res.status(200).json({
        success: true,
        message: '管理员信息获取成功',
        data: {
            user: req.user.userinfo
        }
    });
});

module.exports = router;